package pers.xuehongyan.useat.server.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pers.xuehongyan.useat.server.enity.Ticket;
import pers.xuehongyan.useat.server.exception.ServiceException;
import pers.xuehongyan.useat.server.service.TicketService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xuehongyan
 */
@RestController
@CrossOrigin(origins = {"*", "null"})
@RequestMapping("/ticket")
public class TicketController {
    @Resource
    TicketService ticketService;

    @GetMapping("/")
    public ResponseEntity<List<Ticket>> get(
            @RequestParam("token") String token
    ) {
        try {
            return ResponseEntity.status(HttpStatus.CREATED).body(ticketService.getAll(token));
        } catch (ServiceException e) {
            return ResponseEntity.status(e.getHttpStatus()).build();
        }
    }
}
